Skip to content

[WRONG BRANCH] fix(auth): prefer exact accountId match when importing OAuth identities - #271

Closed
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-legacy-email-fallback-issue
Closed

[WRONG BRANCH] fix(auth): prefer exact accountId match when importing OAuth identities#271
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-legacy-email-fallback-issue

Conversation

@luvs01

@luvs01 luvs01 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent an account-import regression where an incoming credential with accountId could update an earlier legacy email-only row (if that row appeared earlier in the accounts list) and leave a separate stable accountId row, producing duplicate/stale rows.
  • Ensure legacy email-only migration still happens, but only as a fallback when there is no exact accountId match across the account set.

Description

  • Change upsertCredentialByIdentity in src/oauth/store.ts to prefer an exact accountId match across the entire account set when safe.accountId is present, and only then fall back to an email-only match; introduced a matchesEmailOnly helper and an ordered lookup.
  • Preserve the prior email-only upgrade behavior for imports that do not carry an accountId (no functional change for those code paths).
  • Add a focused regression test in tests/account-import.test.ts that seeds an auth.json with an earlier email-only legacy row and a later stable accountId row and verifies the exact accountId row is updated while the legacy row remains unchanged.

Testing

  • Ran the focused tests with bun test tests/account-import.test.ts, which passed (19 tests, 0 failures).
  • Ran bun run typecheck and bun run privacy:scan, both succeeded.
  • Attempted the full suite (bun run test), but the run hit unrelated environment/network failures and timeouts in other integration tests (external package fetches and some test timeouts), so the full-suite run could not complete; the focused regression test and typecheck/privacy checks validate the fix for this change.

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Improved account matching during identity imports to prioritize exact account matches and avoid modifying unrelated legacy records.
    • Prevented duplicate identities when re-importing an existing account.
  • Tests

    • Added coverage for imports involving both legacy email-only records and exact account matches.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fecd2733-05c0-4c15-986f-302023419a31

📥 Commits

Reviewing files that changed from the base of the PR and between 1193075 and c874051.

📒 Files selected for processing (2)
  • src/oauth/store.ts
  • tests/account-import.test.ts
 ________________________________________________________________________________________________________________________
< Don't assume it - prove it. Prove your assumptions in the actual environment - with real data and boundary conditions. >
 ------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/propose-fix-for-legacy-email-fallback-issue

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
@github-actions github-actions Bot changed the title fix(auth): prefer exact accountId match when importing OAuth identities [WRONG BRANCH] fix(auth): prefer exact accountId match when importing OAuth identities Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 13, 2026 01:13

luvs01 commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@luvs01 luvs01 closed this Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant